home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / PrintStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  6.0 KB  |  394 lines

  1. package java.io;
  2.  
  3. import java.util.Formatter;
  4. import java.util.Locale;
  5.  
  6. public class PrintStream extends FilterOutputStream implements Appendable, Closeable {
  7.    private boolean autoFlush;
  8.    private boolean trouble;
  9.    private Formatter formatter;
  10.    private BufferedWriter textOut;
  11.    private OutputStreamWriter charOut;
  12.    private boolean closing;
  13.  
  14.    public PrintStream(OutputStream var1) {
  15.       this(var1, false);
  16.    }
  17.  
  18.    private PrintStream(boolean var1, OutputStream var2) {
  19.       super(var2);
  20.       this.autoFlush = false;
  21.       this.trouble = false;
  22.       this.closing = false;
  23.       if (var2 == null) {
  24.          throw new NullPointerException("Null output stream");
  25.       } else {
  26.          this.autoFlush = var1;
  27.       }
  28.    }
  29.  
  30.    private void init(OutputStreamWriter var1) {
  31.       this.charOut = var1;
  32.       this.textOut = new BufferedWriter(var1);
  33.    }
  34.  
  35.    public PrintStream(OutputStream var1, boolean var2) {
  36.       this(var2, var1);
  37.       this.init(new OutputStreamWriter(this));
  38.    }
  39.  
  40.    public PrintStream(OutputStream var1, boolean var2, String var3) throws UnsupportedEncodingException {
  41.       this(var2, var1);
  42.       this.init(new OutputStreamWriter(this, var3));
  43.    }
  44.  
  45.    public PrintStream(String var1) throws FileNotFoundException {
  46.       this(false, new FileOutputStream(var1));
  47.       this.init(new OutputStreamWriter(this));
  48.    }
  49.  
  50.    public PrintStream(String var1, String var2) throws FileNotFoundException, UnsupportedEncodingException {
  51.       this(false, new FileOutputStream(var1));
  52.       this.init(new OutputStreamWriter(this, var2));
  53.    }
  54.  
  55.    public PrintStream(File var1) throws FileNotFoundException {
  56.       this(false, new FileOutputStream(var1));
  57.       this.init(new OutputStreamWriter(this));
  58.    }
  59.  
  60.    public PrintStream(File var1, String var2) throws FileNotFoundException, UnsupportedEncodingException {
  61.       this(false, new FileOutputStream(var1));
  62.       this.init(new OutputStreamWriter(this, var2));
  63.    }
  64.  
  65.    private void ensureOpen() throws IOException {
  66.       if (this.out == null) {
  67.          throw new IOException("Stream closed");
  68.       }
  69.    }
  70.  
  71.    public void flush() {
  72.       synchronized(this) {
  73.          try {
  74.             this.ensureOpen();
  75.             this.out.flush();
  76.          } catch (IOException var4) {
  77.             this.trouble = true;
  78.          }
  79.  
  80.       }
  81.    }
  82.  
  83.    public void close() {
  84.       synchronized(this) {
  85.          if (!this.closing) {
  86.             this.closing = true;
  87.  
  88.             try {
  89.                this.textOut.close();
  90.                this.out.close();
  91.             } catch (IOException var4) {
  92.                this.trouble = true;
  93.             }
  94.  
  95.             this.textOut = null;
  96.             this.charOut = null;
  97.             this.out = null;
  98.          }
  99.  
  100.       }
  101.    }
  102.  
  103.    public boolean checkError() {
  104.       if (this.out != null) {
  105.          this.flush();
  106.       }
  107.  
  108.       if (this.out instanceof PrintStream) {
  109.          PrintStream var1 = (PrintStream)this.out;
  110.          return var1.checkError();
  111.       } else {
  112.          return this.trouble;
  113.       }
  114.    }
  115.  
  116.    protected void setError() {
  117.       this.trouble = true;
  118.    }
  119.  
  120.    protected void clearError() {
  121.       this.trouble = false;
  122.    }
  123.  
  124.    public void write(int var1) {
  125.       try {
  126.          synchronized(this) {
  127.             this.ensureOpen();
  128.             this.out.write(var1);
  129.             if (var1 == 10 && this.autoFlush) {
  130.                this.out.flush();
  131.             }
  132.          }
  133.       } catch (InterruptedIOException var5) {
  134.          Thread.currentThread().interrupt();
  135.       } catch (IOException var6) {
  136.          this.trouble = true;
  137.       }
  138.  
  139.    }
  140.  
  141.    public void write(byte[] var1, int var2, int var3) {
  142.       try {
  143.          synchronized(this) {
  144.             this.ensureOpen();
  145.             this.out.write(var1, var2, var3);
  146.             if (this.autoFlush) {
  147.                this.out.flush();
  148.             }
  149.          }
  150.       } catch (InterruptedIOException var7) {
  151.          Thread.currentThread().interrupt();
  152.       } catch (IOException var8) {
  153.          this.trouble = true;
  154.       }
  155.  
  156.    }
  157.  
  158.    private void write(char[] var1) {
  159.       try {
  160.          synchronized(this) {
  161.             this.ensureOpen();
  162.             this.textOut.write(var1);
  163.             this.textOut.flushBuffer();
  164.             this.charOut.flushBuffer();
  165.             if (this.autoFlush) {
  166.                for(int var3 = 0; var3 < var1.length; ++var3) {
  167.                   if (var1[var3] == '\n') {
  168.                      this.out.flush();
  169.                   }
  170.                }
  171.             }
  172.          }
  173.       } catch (InterruptedIOException var6) {
  174.          Thread.currentThread().interrupt();
  175.       } catch (IOException var7) {
  176.          this.trouble = true;
  177.       }
  178.  
  179.    }
  180.  
  181.    private void write(String var1) {
  182.       try {
  183.          synchronized(this) {
  184.             this.ensureOpen();
  185.             this.textOut.write(var1);
  186.             this.textOut.flushBuffer();
  187.             this.charOut.flushBuffer();
  188.             if (this.autoFlush && var1.indexOf(10) >= 0) {
  189.                this.out.flush();
  190.             }
  191.          }
  192.       } catch (InterruptedIOException var5) {
  193.          Thread.currentThread().interrupt();
  194.       } catch (IOException var6) {
  195.          this.trouble = true;
  196.       }
  197.  
  198.    }
  199.  
  200.    private void newLine() {
  201.       try {
  202.          synchronized(this) {
  203.             this.ensureOpen();
  204.             this.textOut.newLine();
  205.             this.textOut.flushBuffer();
  206.             this.charOut.flushBuffer();
  207.             if (this.autoFlush) {
  208.                this.out.flush();
  209.             }
  210.          }
  211.       } catch (InterruptedIOException var4) {
  212.          Thread.currentThread().interrupt();
  213.       } catch (IOException var5) {
  214.          this.trouble = true;
  215.       }
  216.  
  217.    }
  218.  
  219.    public void print(boolean var1) {
  220.       this.write(var1 ? "true" : "false");
  221.    }
  222.  
  223.    public void print(char var1) {
  224.       this.write(String.valueOf(var1));
  225.    }
  226.  
  227.    public void print(int var1) {
  228.       this.write(String.valueOf(var1));
  229.    }
  230.  
  231.    public void print(long var1) {
  232.       this.write(String.valueOf(var1));
  233.    }
  234.  
  235.    public void print(float var1) {
  236.       this.write(String.valueOf(var1));
  237.    }
  238.  
  239.    public void print(double var1) {
  240.       this.write(String.valueOf(var1));
  241.    }
  242.  
  243.    public void print(char[] var1) {
  244.       this.write(var1);
  245.    }
  246.  
  247.    public void print(String var1) {
  248.       if (var1 == null) {
  249.          var1 = "null";
  250.       }
  251.  
  252.       this.write(var1);
  253.    }
  254.  
  255.    public void print(Object var1) {
  256.       this.write(String.valueOf(var1));
  257.    }
  258.  
  259.    public void println() {
  260.       this.newLine();
  261.    }
  262.  
  263.    public void println(boolean var1) {
  264.       synchronized(this) {
  265.          this.print(var1);
  266.          this.newLine();
  267.       }
  268.    }
  269.  
  270.    public void println(char var1) {
  271.       synchronized(this) {
  272.          this.print(var1);
  273.          this.newLine();
  274.       }
  275.    }
  276.  
  277.    public void println(int var1) {
  278.       synchronized(this) {
  279.          this.print(var1);
  280.          this.newLine();
  281.       }
  282.    }
  283.  
  284.    public void println(long var1) {
  285.       synchronized(this) {
  286.          this.print(var1);
  287.          this.newLine();
  288.       }
  289.    }
  290.  
  291.    public void println(float var1) {
  292.       synchronized(this) {
  293.          this.print(var1);
  294.          this.newLine();
  295.       }
  296.    }
  297.  
  298.    public void println(double var1) {
  299.       synchronized(this) {
  300.          this.print(var1);
  301.          this.newLine();
  302.       }
  303.    }
  304.  
  305.    public void println(char[] var1) {
  306.       synchronized(this) {
  307.          this.print(var1);
  308.          this.newLine();
  309.       }
  310.    }
  311.  
  312.    public void println(String var1) {
  313.       synchronized(this) {
  314.          this.print(var1);
  315.          this.newLine();
  316.       }
  317.    }
  318.  
  319.    public void println(Object var1) {
  320.       String var2 = String.valueOf(var1);
  321.       synchronized(this) {
  322.          this.print(var2);
  323.          this.newLine();
  324.       }
  325.    }
  326.  
  327.    public PrintStream printf(String var1, Object... var2) {
  328.       return this.format(var1, var2);
  329.    }
  330.  
  331.    public PrintStream printf(Locale var1, String var2, Object... var3) {
  332.       return this.format(var1, var2, var3);
  333.    }
  334.  
  335.    public PrintStream format(String var1, Object... var2) {
  336.       try {
  337.          synchronized(this) {
  338.             this.ensureOpen();
  339.             if (this.formatter == null || this.formatter.locale() != Locale.getDefault()) {
  340.                this.formatter = new Formatter(this);
  341.             }
  342.  
  343.             this.formatter.format(Locale.getDefault(), var1, var2);
  344.          }
  345.       } catch (InterruptedIOException var6) {
  346.          Thread.currentThread().interrupt();
  347.       } catch (IOException var7) {
  348.          this.trouble = true;
  349.       }
  350.  
  351.       return this;
  352.    }
  353.  
  354.    public PrintStream format(Locale var1, String var2, Object... var3) {
  355.       try {
  356.          synchronized(this) {
  357.             this.ensureOpen();
  358.             if (this.formatter == null || this.formatter.locale() != var1) {
  359.                this.formatter = new Formatter(this, var1);
  360.             }
  361.  
  362.             this.formatter.format(var1, var2, var3);
  363.          }
  364.       } catch (InterruptedIOException var7) {
  365.          Thread.currentThread().interrupt();
  366.       } catch (IOException var8) {
  367.          this.trouble = true;
  368.       }
  369.  
  370.       return this;
  371.    }
  372.  
  373.    public PrintStream append(CharSequence var1) {
  374.       if (var1 == null) {
  375.          this.print("null");
  376.       } else {
  377.          this.print(var1.toString());
  378.       }
  379.  
  380.       return this;
  381.    }
  382.  
  383.    public PrintStream append(CharSequence var1, int var2, int var3) {
  384.       Object var4 = var1 == null ? "null" : var1;
  385.       this.write(((CharSequence)var4).subSequence(var2, var3).toString());
  386.       return this;
  387.    }
  388.  
  389.    public PrintStream append(char var1) {
  390.       this.print(var1);
  391.       return this;
  392.    }
  393. }
  394.